//
//  ReadDetailsCollectionCellOfTableCell.m
//  aMoment
//
//  Created by dllo on 15/10/11.
//  Copyright © 2015年 LuckyHan. All rights reserved.
//

#import "ReadDetailsCollectionCellOfTableCell.h"
#import "AllHeaderFiles.h"

@implementation ReadDetailsCollectionCellOfTableCell

- (void)dealloc
{
    [_titleLabel release];
    [_coverImageView release];
    [_contentLabel release];
    [_readDetails release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}

- (void)createViews
{
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
    [self.contentView addSubview:_titleLabel];
    [_titleLabel release];
    
    _coverImageView = [[UIImageView alloc] init];
//    _coverImageView.backgroundColor = [UIColor grayColor];
    _coverImageView.contentMode = UIViewContentModeScaleAspectFill;
    _coverImageView.clipsToBounds = YES;
    [self.contentView addSubview:_coverImageView];
    [_coverImageView release];
    
    _contentLabel = [[UILabel alloc] init];
    _contentLabel.font = [UIFont systemFontOfSize:FONTSIZE_MIDDLE];
    _contentLabel.numberOfLines = 0;
    [self.contentView addSubview:_contentLabel];
    [_contentLabel release];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _titleLabel.frame = CGRectMake(20 * FIT_WIDTH, 15 * FIT_HEIGHT, SCREEN_WIDTH - 40 * FIT_WIDTH, 20 * FIT_HEIGHT);
    _coverImageView.frame = CGRectMake(_titleLabel.X, _titleLabel.Y + _titleLabel.Height + _titleLabel.Y, 155 * FIT_WIDTH, 70 * FIT_HEIGHT);
    _contentLabel.frame = CGRectMake(_coverImageView.X + _coverImageView.Width + 5 * FIT_WIDTH, _coverImageView.Y, _titleLabel.Width - _coverImageView.Width - 5 * FIT_WIDTH, _coverImageView.Height);
}

- (void)setReadDetails:(ReadDetails *)readDetails
{
    if (_readDetails != readDetails) {
        [_readDetails release];
        _readDetails = [readDetails retain];
    }
    _titleLabel.text = _readDetails.title;
//    [_coverImageView setImageWithURL:[NSURL URLWithString:_readDetails.coverimg]];
    [_coverImageView setImageWithURL:[NSURL URLWithString:_readDetails.coverimg] placeholderImage:[UIImage imageNamed:@"placeholder-image"]];
    _contentLabel.text = _readDetails.content;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
